package com.bsoft.client.transport;

import com.alibaba.fastjson.JSON;
import com.bsoft.core.common.RpcResponse;
import com.bsoft.core.protocol.MessageProtocol;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 客户端消息响应处理类
 */
@Slf4j
public class RpcResponseHandler extends SimpleChannelInboundHandler<MessageProtocol<RpcResponse>> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageProtocol<RpcResponse> protocol) throws Exception {
        log.info("got response from server：{}", JSON.toJSONString(protocol));
        // 监听到服务端的响应，缓存栅栏可以解除，让future获取结果
        UnsolvedResponseCache.complete(protocol);
    }
}
